﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
    CodeBehind="Managers.aspx.cs" Inherits="ImgForecast.admin.Managers" %>

<%@ Register Assembly="obout_Grid_NET" Namespace="Obout.Grid" TagPrefix="cc1" %>
<%@ Register Assembly="obout_Interface" Namespace="Obout.Interface" TagPrefix="cc2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <cc1:Grid ID="Grid1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
        CallbackMode="true" Serialize="true" AllowAddingRecords="false" PageSize="100">
        <ClientSideEvents OnClientCallbackError="true" />
        <Columns>
            <cc1:Column ID="Column1" DataField="UserId" Visible="false" ReadOnly="true" HeaderText="User ID"
                Width="100" runat="server" />
            <cc1:Column ID="Column2" DataField="LoweredUserName" HeaderText="Username" Width="100"
                runat="server" ReadOnly="true" />
            <cc1:Column ID="Column3" DataField="Lastname" HeaderText="Lastname" Width="150" runat="server" />
            <cc1:Column ID="Column4" DataField="Firstname" HeaderText="Firstname" Width="150"
                runat="server" />
            <cc1:Column ID="Column5" DataField="OfficeID" HeaderText="Office" Width="180" runat="server">
                <TemplateSettings TemplateId="OfficeTemplate" EditTemplateId="OfficeEditTemplate" />
            </cc1:Column>
            <cc1:Column ID="Column6" DataField="DivisionID" HeaderText="Division" Width="180"
                runat="server">
                <TemplateSettings TemplateId="DivisionTemplate" EditTemplateId="DivisionEditTemplate" />
            </cc1:Column>
            <cc1:Column ID="Column7" HeaderText="Edit" AllowEdit="true" Width="125" runat="server" />
        </Columns>
        <Templates>
            <cc1:GridTemplate runat="server" ID="OfficeTemplate">
                <Template>
                    <%# Container.DataItem["Office"]%>
                </Template>
            </cc1:GridTemplate>
            <cc1:GridTemplate runat="server" ID="OfficeEditTemplate" ControlID="ddlOffice" ControlPropertyName="value">
                <Template>
                    <cc2:OboutDropDownList ID="ddlOffice" runat="server" DataSourceID="SqlDataSource3"
                        DataTextField="Shortname" DataValueField="OfficeID">
                    </cc2:OboutDropDownList>
                </Template>
            </cc1:GridTemplate>
            <cc1:GridTemplate runat="server" ID="DivisionTemplate">
                <Template>
                    <%# Container.DataItem["Division"]%>
                </Template>
            </cc1:GridTemplate>
            <cc1:GridTemplate runat="server" ID="DivisionEditTemplate" ControlID="ddlDivision"
                ControlPropertyName="value">
                <Template>
                    <cc2:OboutDropDownList ID="ddlDivision" runat="server" DataSourceID="SqlDataSource4"
                        DataTextField="Name" DataValueField="DivisionID">
                    </cc2:OboutDropDownList>
                </Template>
            </cc1:GridTemplate>
        </Templates>
    </cc1:Grid>
    <a href="AddManager.aspx">Add Manager >></a><br />
    Username:<asp:DropDownList ID="UsernameToDelete" runat="server" DataSourceID="SqlDataSource2"
        DataTextField="LoweredUserName" DataValueField="LoweredUserName">
    </asp:DropDownList>
    &nbsp;<asp:Button ID="BtnDeleteManager" runat="server" Text="Delete Manager" OnClick="BtnDeleteManager_Click" />
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>"
        SelectCommand="SELECT     aspnet_Users.LoweredUserName, UserProfiles.OfficeID, UserProfiles.DivisionID, UserProfiles.Firstname, UserProfiles.Lastname, Offices.ShortName AS Office, 
                      Divisions.Name AS Division, aspnet_Users.UserId
FROM         aspnet_Users INNER JOIN
                      UserProfiles ON aspnet_Users.UserId = UserProfiles.UserID INNER JOIN
                      Offices ON UserProfiles.OfficeID = Offices.OfficeID INNER JOIN
                      Divisions ON UserProfiles.DivisionID = Divisions.DivisionID" InsertCommand="INSERT INTO [UserProfiles] ([UserID], [OfficeID], [DivisionID], [Firstname], [Lastname]) VALUES (@UserID, @OfficeID, @DivisionID, @Firstname, @Lastname)"
        UpdateCommand="UPDATE [UserProfiles] SET [OfficeID] = @OfficeID, [DivisionID] = @DivisionID, [Firstname] = @Firstname, [Lastname] = @Lastname WHERE [UserID] = @UserID">
        <DeleteParameters>
            <asp:Parameter Name="UserID" Type="Object" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="UserID" Type="Object" />
            <asp:Parameter Name="OfficeID" Type="Int32" />
            <asp:Parameter Name="DivisionID" Type="Int32" />
            <asp:Parameter Name="Firstname" Type="String" />
            <asp:Parameter Name="Lastname" Type="String" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="OfficeID" Type="Int32" />
            <asp:Parameter Name="DivisionID" Type="Int32" />
            <asp:Parameter Name="Firstname" Type="String" />
            <asp:Parameter Name="Lastname" Type="String" />
            <asp:Parameter Name="UserID" Type="String" />
        </UpdateParameters>
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>"
        SelectCommand="SELECT [LoweredUserName] FROM [vw_aspnet_Users] ORDER BY [LoweredUserName]">
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>"
        SelectCommand="SELECT [Shortname], [OfficeID] FROM [Offices] ORDER BY [Name]">
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>"
        SelectCommand="SELECT [Name], [DivisionID] FROM [Divisions] ORDER BY [Name]">
    </asp:SqlDataSource>
</asp:Content>
